package lx.jdbc;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class JdbcSelect {
    public static void main(String[] args) throws  Exception {
        Class.forName("com.mysql.jdbc.Driver");
        String url = "jdbc:mysql://localhost:3306/test?useSSL=false";
        String username = "root";
        String password = "1102";
        Connection connection = DriverManager.getConnection(url,username,password);
        //创建陈述句对象
        Statement statement = connection.createStatement();
        //执行查询
        String sql = "SELECT id, username, password FROM `user`";
        ResultSet set = statement.executeQuery(sql);
        //获取数据
        while(set.next()){
            int id = set.getInt(1);
            String name = set.getString(2);
            System.out.println("id = "+id+";"+"username = "+name);
        }

    }
}
